package teacher

import (
	"anban/controllers"
	"anban/service"
	"github.com/astaxie/beego"
	"html/template"
	"strconv"
)

type SafeNoticeController struct {
	controllers.BaseController
}

func (c *SafeNoticeController) Index() {
	p := map[string]interface{}{}
	p["userId"] = c.GetSession("userId")
	p["withStudent"] = true
	_, c.Data["classList"] = service.GetClassList(p)

	c.Data["title"] = "门禁历史"
	c.Data["xsrfdata"] = template.HTML(c.XSRFFormHTML())
	c.TplName = "teacher/safe-history.html"
}

func (c *SafeNoticeController) Detail() {
	id := c.Ctx.Input.Param(":id")

	p := map[string]interface{}{}
	p["id"] = id
	c.Data["student"] = service.GetStudentInfo(p)

	c.Data["id"] = id
	c.Data["title"] = "门禁历史"
	c.Data["xsrfdata"] = template.HTML(c.XSRFFormHTML())
	c.TplName = "teacher/safe-history-detail.html"
}

func (c *SafeNoticeController) DetailLoadMore() {
	count, _ := beego.AppConfig.Int("loadcount")
	curPage, _ := strconv.Atoi(c.GetString("p"))
	if curPage <= 0 {
		curPage = 1
	}
	id := c.Ctx.Input.Param(":id")
	p := map[string]interface{}{}
	p["studentId"] = id
	p["relation"] = true
	p["convert"] = true
	p["curPage"] = curPage
	p["perCount"] = count
	_, c.Data["safeNoticeList"] = service.GetSafeNoticeList(p)
	c.TplName = "teacher/safe-history-detail-list.html"
}